#include<bits/stdc++.h>
using namespace std;
const int N=200003,M=1000003;
long long d[N],v[N],a[N],p[M],n,m,L,V,cnt1,cnt2,c;
struct nod{
    long long l,r;
}b[N];
bool cmp(nod x,nod y){
    if(x.r==y.r) return x.l<y.l;
    return x.r<y.r;
}
long long fnd1(long long x){
    long long l=1,r=m;
    while(l<r){
        long long mid=(l+r)/2;
        if(p[mid]>=x) r=mid;
        else l=mid+1;
    }
    return l;
}
long long fnd2(long long x){
    long long l=0,r=m;
    while(l<r){
        long long mid=(l+r+1)/2;
        if(p[mid]<=x) l=mid;
        else r=mid-1;
    }
    return l;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T; cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        for(int i=0;i<=n+2;i++) b[i].l=b[i].r=-1;
        cnt1=c=0,cnt2=m;
        for(int i=1;i<=n;i++) cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++) cin>>p[i];
        for(int i=1;i<=n;i++){
            if(d[i]>p[m]) continue;
            if(a[i]>0){
                long long x;
                if(v[i]<V){
                    x=d[i]+ceil((double)(V*V-v[i]*v[i])/a[i]/2);
                    if(2*a[i]*(x-d[i])<=V*V-v[i]*v[i]) x++;
                    if(2*a[i]*(x-d[i])<=V*V-v[i]*v[i]) x++;
                    if(2*a[i]*(x-1-d[i])>V*V-v[i]*v[i]) x--;
                    if(2*a[i]*(x-1-d[i])>V*V-v[i]*v[i]) x--;
                }
                else x=d[i];
                if(x>p[m]||(v[i]==V&&x==p[m])) continue;
                b[i].l=fnd1(x),b[i].r=m,cnt1++;
                continue;
            }
            if(a[i]==0){
                if(v[i]>V)
                    b[i].l=fnd1(d[i]),b[i].r=m,cnt1++;
                continue;
            }
            if(a[i]<0){
                if(v[i]<V) continue;
                long long x=d[i]+floor((double)(V*V-v[i]*v[i])/a[i]/2);
                if(-2*a[i]*(x-d[i])>=v[i]*v[i]-V*V) x--;
                if(-2*a[i]*(x-d[i])>=v[i]*v[i]-V*V) x--;
                if(-2*a[i]*(x+1-d[i])<v[i]*v[i]-V*V) x++;
                if(-2*a[i]*(x+1-d[i])<v[i]*v[i]-V*V) x++;
                b[i].l=fnd1(d[i]),b[i].r=fnd2(x);
                if(b[i].l<=b[i].r) cnt1++;
                else b[i].l=b[i].r=-1;
                continue;
            }
        }
        sort(b+1,b+n+1,cmp);
        for(int i=1;i<=n;i++){
            if(b[i].l==-1) continue;
            if(b[i].l<=c) continue;
            c=b[i].r,cnt2--;
        }
        cout<<cnt1<<" "<<cnt2<<endl;
    }
    return 0;
}
